package com.yunyao.dao.service.system.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yunyao.common.constant.enums.DataDeletedStatus;
import com.yunyao.common.web.util.StringUtils;
import com.yunyao.dao.mapper.EstProcessStartRecordMapper;
import com.yunyao.dao.model.EstProcessStartRecord;
import com.yunyao.dao.service.system.IEstProcessStartRecordService;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 审批流程发起记录 服务实现类
 * </p>
 *
 * @author xingjishuai
 * @since 2024-07-02
 */
@Service
public class EstProcessStartRecordServiceImpl extends ServiceImpl<EstProcessStartRecordMapper, EstProcessStartRecord> implements IEstProcessStartRecordService {

    @Override
    public EstProcessStartRecord getByProcessInstanceId(String processInstanceId) {
        if (StringUtils.isBlank(processInstanceId)) {
            return null;
        }
        LambdaQueryWrapper<EstProcessStartRecord> wrapper =
                new LambdaQueryWrapper<EstProcessStartRecord>()
                .eq(EstProcessStartRecord::getProcessInstanceId, processInstanceId)
                .eq(EstProcessStartRecord::getIsDeleted, DataDeletedStatus.NO.getType());
        return getOne(wrapper);
    }

    @Override
    public List<EstProcessStartRecord> listByProcessInstanceIdList(List<String> processInstanceIdList) {
        if (CollectionUtils.isEmpty(processInstanceIdList)) {
            return List.of();
        }
        LambdaQueryWrapper<EstProcessStartRecord> wrapper =
                new LambdaQueryWrapper<EstProcessStartRecord>()
                        .in(EstProcessStartRecord::getProcessInstanceId, processInstanceIdList)
                        .eq(EstProcessStartRecord::getIsDeleted, DataDeletedStatus.NO.getType());
        return list(wrapper);
    }

    @Override
    public List<EstProcessStartRecord> listByBizId(String bizId) {
        if (StringUtils.isBlank(bizId)) {
            return List.of();
        }
        LambdaQueryWrapper<EstProcessStartRecord> wrapper =
                new LambdaQueryWrapper<EstProcessStartRecord>()
                .eq(EstProcessStartRecord::getBizId, bizId)
                .eq(EstProcessStartRecord::getIsDeleted, DataDeletedStatus.NO.getType());
        return list(wrapper);
    }
}
